package com.example.code06;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class NewsAdapter extends ArrayAdapter<News> {
    private List<News> newsList;
    private Context context;
    private int resourceid;
    public NewsAdapter(Context context,int resourceid,List<News> newsList){
        super(context,resourceid,newsList);
        this.context=context;
        this.resourceid=resourceid;
        this.newsList=newsList;
    }
    public View getView(int position, View converView, ViewGroup parent){
        News news=getItem(position);
        View view;
        view= LayoutInflater.from(getContext()).inflate(resourceid,parent,false);
        TextView textView1=view.findViewById(R.id.tv_title);
        TextView textView2=view.findViewById(R.id.tv_author);
        ImageView imageView=view.findViewById(R.id.iv_image);
        textView1.setText(news.getmTitle());
        textView2.setText(news.getmAuthor());
        imageView.setImageBitmap(news.getmImage());
        return view;
    }

}
